package crm.implementor;


import crm.daoInterfaces.SalesPersonDao;
import crm.dbhandelling.Crude;
import crm.dto.SalesPerson;

public class SalesPersonImp extends Crude implements SalesPersonDao
{

	private String className = new SalesPerson().getClass().getName();
	@Override
	public void add(SalesPerson att) throws Exception
	{
		super.insert(att);	
	}

	@Override
	public void update(SalesPerson att) 
	{
		super.update(className, "salesPersonName", att.getSalesPersonName(), "salesPersonId", att.getAutoSalesPersonId()+"");
		super.update(className, "status", att.getStatus()+"", "salesPersonId",att.getAutoSalesPersonId()+"");
	}

	@Override
	public void delete(SalesPerson att) {
		super.delete(className, "salesPersonId",att.getAutoSalesPersonId()+"");
		
	}

	

	@Override
	public SalesPerson[] retrieveAll() throws Exception
	{
		Object[] att=super.retreiveAll(className);
		SalesPerson[] s=new SalesPerson[att.length];
		for(int i=0;i<s.length;i++)
				s[i]=(SalesPerson) att[i];
		return s;
		
	}

	@Override
	public SalesPerson retrieve( String conditionField,
			String conditionValue) throws Exception
	{
		SalesPerson att=(SalesPerson) super.retreive(className, conditionField, conditionValue);
		return att;
	}

	@Override
	public SalesPerson[] retrieveArray( String conditionField,String conditionValue) throws Exception 
	{
		Object[] att=super.retreiveArrayOnCondition(className, conditionField, conditionValue);
		SalesPerson[] s=new SalesPerson[att.length];
		for(int i=0;i<s.length;i++)
				s[i]=(SalesPerson) att[i];
		return s;
	}

	@Override
	public int getAutoGenratedKey()
	  {
		 int key=super.getAutoGenratedKey(className,"autosalesPersonId") ;
		 return key;
	  }

}
